package com.joshondesign.sdljava.gfx;

public class LabelNode extends Control {
    private String text;
    private HAlign halign = HAlign.Left;
    private SColor textColor = SColor.BLACK;

    public LabelNode setText(String text) {
        this.text = text;
        return this;
    }

    @Override
    public void draw(GFX gfx) {
        gfx.setPaint(textColor);
        GFX.TextMetrics metrics = gfx.measureString(this.font, this.text);
        if(halign == HAlign.Left) {
            gfx.drawString(this.font, this.text, this.x, this.y);
        }
        if(halign == HAlign.Right) {
            gfx.drawString(this.font, this.text, this.x - metrics.minx - metrics.maxx, this.y);
        }
    }

    public LabelNode setHAlign(HAlign align) {
        this.halign = align;
        return this;
    }

    public LabelNode setTextColor(SColor textColor) {
        this.textColor = textColor;
        return this;
    }

    public static enum HAlign {
        Left,
        Right
    }

}
